<template>
        <table class="table table-bordered">
        <tr>
                <td>投资项目名称</td>
                <td><input type="text"  v-model="info.I_Name" placeholder="请输入投资项目名称"></td>
            </tr>
            <tr>
                <td>投资项目总额度</td>
                <td><input type="text" v-model="info.I_Budget"  placeholder="请输入投资项目总额度"></td>
            </tr>
        <tr>
            <td colspan="2">
            <input type="button" @click="UpdInvest" value="修改" >
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import { useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();

const id = route.query.Iid;


const info = ref({
    
    I_Name: '',
    I_Budget: '',
    
});

onMounted(() => {
    Ft();
})


const Ft = ()=>{
   
    axios.get('http://localhost:58004/api/invest/GetInvestInfo',
    {
        params:{
            Iid:id,
            
        }
    })
    .then((res)=>{
       info.value.I_Name = res.data.I_Name;
       info.value.I_Budget = res.data.I_Budget;
        
        
    })
    .catch((err)=>{
        console.log(err);
    })
}


const UpdInvest = ()=>{
    axios.put('http://localhost:58004/api/invest/UpdInvestInfo',
    {
        I_Id:id,
        I_Name:info.value.I_Name,
        I_Budget:info.value.I_Budget,
        
    })
    .then((res)=>{
        if(res.data>0){
            alert('修改成功');
            router.push('/SelInvest');
        }
        else if(res.data==-1)
         {
            alert('当前项目有人投资无法修改');
            return;
        }
        else{
            alert('修改失败');
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>